package com.IOT_LSL;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

import java.util.concurrent.TimeoutException;

public class LineChart_DetailsMakerView extends MarkerView {
    private TextView time;
    private TextView info;

    public LineChart_DetailsMakerView(Context context, int layoutResource) {
        super(context, layoutResource);
        time = findViewById(R.id.linechart_tv_time);
        info = findViewById(R.id.linechart_tv_info);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth()/2),-getHeight());
    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        super.refreshContent(e, highlight);
        int cnt = highlight.getDataSetIndex();
        try {
            time.setText("时间: "+String.valueOf((int)e.getX()).concat(":00"));
            //收入
            if (e.getY() == 0) {
                info.setText("0");
            } else {
                if(cnt==0)
                    info.setText("温度: "+String.valueOf((int)e.getY()).concat("℃"));
                else
                    info.setText("湿度: "+String.valueOf((int)e.getY()).concat("%"));
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        super.refreshContent(e, highlight);
    }
}
